﻿#define PERFORMANCE_TEST
#if PERFORMANCE_TEST

using Nemerle.Collections;
using Nemerle.Text;
using Nemerle.Utility;
using Nemerle2.Compiler;
using NUnit.Framework;

using System;
using System.Console;
using System.Collections.Generic;
using System.Linq;
using System.Diagnostics;

using SCG = System.Collections.Generic;

namespace Test
{
  /// <summary>
  /// Description of PerformanceTests.
  /// </summary>

  [TestFixture]
  public class PerformanceTests : AssemblyTests
  {
    [Test]
    public Test() : void
    {
      Console.WriteLine();

      def timer = Stopwatch.StartNew();
      def print(msg : string) : void
      {
        WriteLine(msg);
        timer.Reset();
        timer.Start();
      }

      def assemblies = AllAssembliesProject.LoadedAssemblies;

      print($"time of loading assemblies  = $(timer.Elapsed)");

      def getAllTypesRecurse(topLevelTypes : Seq[ITypeInfo], typesList : SCG.List[_])
      {
        foreach (ty in topLevelTypes)
        {
          typesList.Add(ty);
          getAllTypesRecurse(ty.GetNestedTypes(), typesList);
        }
      }

      def lst = SCG.List();

      foreach(ass in assemblies)
        getAllTypesRecurse(ass.TopLevelTypes, lst);

      print($"time of getting total types = $(timer.Elapsed), type count = $(lst.Count)");

      def lst = SCG.List();

      foreach(ass in assemblies)
        getAllTypesRecurse(ass.TopLevelTypes, lst);

      print($"time of getting total types = $(timer.Elapsed), type count = $(lst.Count)");

      def typesTreeNode = NProject(NSolution(Provider)).TypesTreeRoot;

      foreach (assm in assemblies)
        typesTreeNode.AddFromReferencedAssembly(assm);

      print($"Time build types tree of standart assemblies = $(timer.Elapsed)");

      def system = typesTreeNode["System"].Children;
      Assert.Greater(system.Length, 10);

      //Console.WriteLine("Press enter...");
      //_ = Console.ReadLine();
    }
  }
}
#endif